<?php
ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\brand\Brand as mBrand;
use Biz\model\brand\BrandOrder;
use Biz\model\brand\BrandPackage as mBrandPackage;

//$list = mBrand::getAllBrand();
$list = mBrand::selectByWhere(['uid[>]' => 0, 'status' => mBrand::STATUS_USING, 'brand_type[>=]' => mBrand::BRAND_TYPE_COMMON, 'pack_type' => 0]);
foreach ($list as $row) {
    if ($row['uid'] > 0) {
        switch ($row['brand_type']) {
            case mBrand::BRAND_TYPE_COMMON:
                mBrand::update(['pack_type' => mBrandPackage::PACK_TYPE_NORMAL], ['id' => $row['id']]);
                break;
            case mBrand::BRAND_TYPE_BEST:
            case mBrand::BRAND_TYPE_SUPER:
                mBrand::update(['pack_type' => mBrandPackage::PACK_TYPE_PRO], ['id' => $row['id']]);
                break;
        }
    }
}

$list = BrandOrder::select('*', [
        'order_status' => BrandOrder::ORDER_STATUS_FINISHED,
        'pay_status' => BrandOrder::PAY_STATUS_PAID,
        'pack_type' => 0,
    ]
);
$packList = mBrandPackage::getPackList();
$packList = array_values($packList);
$packList = array_column($packList, null, 'id');
foreach ($list as $row) {
    if (isset($packList[$row['package_id']]) && $packList[$row['package_id']]) {
        $packType = $packList[$row['package_id']]['pack_type'];
        BrandOrder::update(['pack_type' => $packType], ['id' => $row['id']]);
    }
}